﻿<Window x:Name="Window" x:Class="NeonMika.NetduinoControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:prop="clr-namespace:NeonMika.NetduinoControl.Properties"
        Title="MainWindow" Height="800" Width="1000" Loaded="Window_Loaded">
    <Window.Resources>
       
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <DockPanel>
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Width="3*"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>

                    <!-- Row 1 -->
                    <TextBlock Grid.Row="0" Grid.Column="0" Margin="2,2,2,2">Netduino IP:</TextBlock>
                    <TextBox Grid.Row="0" Grid.Column="1" Name="TextBoxIP" Margin="2,2,2,2" Text="{Binding IP}"></TextBox>
                    <Button Grid.Row="0" Grid.Column="2" Name="ButtonUpdateAllPins" Margin="2,2,2,2" Click="ButtonUpdateAllPins_Click">Update all pins</Button>
                    <!-- Row 2 -->
                    <TextBlock Grid.Row="1" Grid.Column="0" Margin="2,2,2,2">Send raw command:</TextBlock>
                    <TextBox Grid.Row="1" Grid.Column="1" Name="TextBoxRawCommand" Margin="2,2,2,2"></TextBox>
                    <Button Grid.Row="1" Grid.Column="2" Name="ButtonRawCommand" Click="ButtonRawCommand_Click" Margin="2,2,2,2">Send</Button>

                    <!-- Row 3 -->
                    <TextBlock Grid.Row="2" Grid.Column="0" Margin="2,2,2,2">Switch pin:</TextBlock>
                    <ComboBox SelectedIndex="0" Grid.Row="2" Grid.Column="1" Name="ComboBoxSwitchPin" Margin="2,2,2,2">
                        <ComboBoxItem IsEnabled="False">Select pin</ComboBoxItem>
                        <ComboBoxItem>0</ComboBoxItem>
                        <ComboBoxItem>1</ComboBoxItem>
                        <ComboBoxItem>2</ComboBoxItem>
                        <ComboBoxItem>3</ComboBoxItem>
                        <ComboBoxItem>4</ComboBoxItem>
                        <ComboBoxItem>5</ComboBoxItem>
                        <ComboBoxItem>6</ComboBoxItem>
                        <ComboBoxItem>7</ComboBoxItem>
                        <ComboBoxItem>8</ComboBoxItem>
                        <ComboBoxItem>9</ComboBoxItem>
                        <ComboBoxItem>10</ComboBoxItem>
                        <ComboBoxItem>11</ComboBoxItem>
                        <ComboBoxItem>12</ComboBoxItem>
                        <ComboBoxItem>13</ComboBoxItem>
                    </ComboBox>
                    <Button Grid.Row="2" Grid.Column="2" Name="ButtonSwitchPin" Margin="2,2,2,2" Click="ButtonSwitchPin_Click">Send</Button>

                    <!-- Row 4 -->
                    <TextBlock Grid.Row="3" Grid.Column="0" Margin="2,2,2,2">Set pin:</TextBlock>
                    <DockPanel Grid.Row="3" Grid.Column="1" Margin="2,2,2,2">
                        <CheckBox Name="TextBoxSetPinState" VerticalAlignment="Center" Margin="2,2,2,2" Content="Active" FlowDirection="RightToLeft"></CheckBox>
                        <ComboBox SelectedIndex="0" Name="ComboBoxSetPinPin" Margin="2,2,2,2">
                            <ComboBoxItem IsEnabled="False">Select pin</ComboBoxItem>
                            <ComboBoxItem>0</ComboBoxItem>
                            <ComboBoxItem>1</ComboBoxItem>
                            <ComboBoxItem>2</ComboBoxItem>
                            <ComboBoxItem>3</ComboBoxItem>
                            <ComboBoxItem>4</ComboBoxItem>
                            <ComboBoxItem>5</ComboBoxItem>
                            <ComboBoxItem>6</ComboBoxItem>
                            <ComboBoxItem>7</ComboBoxItem>
                            <ComboBoxItem>8</ComboBoxItem>
                            <ComboBoxItem>9</ComboBoxItem>
                            <ComboBoxItem>10</ComboBoxItem>
                            <ComboBoxItem>11</ComboBoxItem>
                            <ComboBoxItem>12</ComboBoxItem>
                            <ComboBoxItem>13</ComboBoxItem>
                        </ComboBox>
                    </DockPanel>
                    <Button Grid.Row="3" Grid.Column="2" Name="ButtonSetPin" Margin="2,2,2,2" Click="ButtonSetPin_Click">Send</Button>

                    <!-- Row  5 -->
                    <TextBlock Grid.Row="4" Grid.Column="0" Margin="2,2,2,2">Digital pins:</TextBlock>
                    <!-- Row  6 -->
                    <ListBox Name="ListBoxDigitalPins" ItemsSource="{Binding DigitalPins}" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Margin="2,2,2,2">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem" >
                                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <DataTemplate.Resources>
                                    <Style TargetType="Ellipse">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsPWM}" Value="true">
                                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Value}" Value="1">
                                                <Setter Property="Fill" Value="Green"></Setter>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Value}" Value="0">
                                                <Setter Property="Fill" Value="Red"></Setter>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                    <Style TargetType="Grid">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsPWM}" Value="true">
                                                <Setter Property="Visibility" Value="Visible"></Setter>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding IsPWM}" Value="false">
                                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </DataTemplate.Resources>
                                <DockPanel>
                                    <TextBlock VerticalAlignment="Center" DockPanel.Dock="Left" Text="{Binding ID}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock VerticalAlignment="Center" DockPanel.Dock="Left" Margin="2,2,2,2">: </TextBlock>
                                    <Ellipse VerticalAlignment="Center" DockPanel.Dock="Left" Margin="2,2,2,2" Height="20" Width="{Binding Height, RelativeSource={RelativeSource Self}}"></Ellipse>
                                    <Grid VerticalAlignment="Center" Margin="2,2,2,2">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"></RowDefinition>
                                            <RowDefinition Height="Auto"></RowDefinition>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                                            <ColumnDefinition Width="4*"></ColumnDefinition>
                                            <ColumnDefinition Width="*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <!-- 1. Row -->
                                        <TextBlock Grid.Row="0" Grid.Column="0" Margin="2,2,2,2">Period</TextBlock>
                                        <Slider Name="SliderPeriod" Grid.Row="0" Grid.Column="1" Margin="2,2,2,2" IsSnapToTickEnabled="True" Orientation="Horizontal" Maximum="20000" SmallChange="10" Value="{Binding Period}" LargeChange="200"></Slider>
                                        <TextBlock Grid.Row="0" Grid.Column="2" Margin="2,2,2,2" Text="{Binding Value, ElementName=SliderPeriod, Mode=OneWay}"></TextBlock>

                                        <!-- 2. Row -->
                                        <TextBlock Grid.Row="1" Grid.Column="0" Margin="2,2,2,2">Duration</TextBlock>
                                        <Slider Uid="{Binding ID}" Name="SliderDuration" Grid.Row="1" Grid.Column="1" Margin="2,2,2,2" IsSnapToTickEnabled="True" Orientation="Horizontal" Value="{Binding Duration}" Maximum="{Binding Value, ElementName=SliderPeriod}" SmallChange="10" LargeChange="200"  PreviewMouseUp="SliderDuration_MouseUp"></Slider>
                                        <TextBlock Grid.Row="1" Grid.Column="2" Margin="2,2,2,2" Text="{Binding Value, ElementName=SliderDuration, Mode=OneWay}"></TextBlock>
                                    </Grid>
                                </DockPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <Grid Margin="2,2,2,2" Grid.Row="5" Grid.Column="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Button Grid.Row="0" Name="ButtonUpdateDigitalPins" Margin="2,2,2,2" Click="ButtonUpdateDigitalPins_Click">Update digital pins</Button>
                        <Button Grid.Row="1" Name="ButtonUpdatePWMPins" Margin="2,2,2,2" Click="ButtonUpdatePWMPins_Click">Update PWM pins</Button>
                    </Grid>
                    

                    <!-- Row  7 -->
                    <TextBlock Grid.Row="6" Grid.Column="0" Margin="2,2,2,2">Analog pins:</TextBlock>

                    <!-- Row  8 -->
                    <ListBox Name="ListBoxAnalogPins" Grid.Row="7" Grid.Column="0" Margin="2,2,2,2" Grid.ColumnSpan="2" ItemsSource="{Binding AnalogPins}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>                                
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock VerticalAlignment="Center" Name="TexBlockDigitalPinId" Text="{Binding ID}" Margin="2,2,2,2"></TextBlock>
                                    <TextBlock VerticalAlignment="Center" Margin="2,2,2,2">:</TextBlock>
                                    <TextBlock VerticalAlignment="Center" Margin="2,2,2,2" Text="{Binding Value}"></TextBlock>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <Button Grid.Row="7" Grid.Column="2" Name="ButtonUpdateAnalogPins" Margin="2,2,2,2" Click="ButtonUpdateAnalogPins_Click">Update analog pins</Button>
                </Grid>
            </ScrollViewer>
        </DockPanel>

        <GridSplitter Grid.Column="0" Width="2" />
        
        <DockPanel Grid.Column="1">
            <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                <TabControl>
                    <TabItem Header="Url description">
                        <TextBlock Text="{x:Static prop:Resources.NetduinoCommands}"></TextBlock>
                    </TabItem>
                    <TabItem Header="Last response">
                        <TextBlock Name="TextBoxLastResponse"></TextBlock>
                    </TabItem>
                </TabControl>
            </ScrollViewer>
        </DockPanel>
    </Grid>
</Window>
